package com.bbx.taxi.client.widget.ScrollView;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.HorizontalScrollView;

/**
 * @Path com.bbx.taxi.client.widget.ScrollView.MyHorizontalScrollView.java
 * @Author 严旭文
 * @Date 2016-4-8 下午2:29:44
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 */
public class MyHorizontalScrollView extends HorizontalScrollView {
	public static final int LEFT=1;
	public static final int RIGHT=2;
	public static final int CENTER=3;
	/**设置误差*/
	public  final int error=50;
	public interface ScrollViewListener {
        /**左右滚动监听*/
		void onScrollChanged(int fangxiang);

	}

	private ScrollViewListener scrollViewListener = null;

	public MyHorizontalScrollView(Context context) {
		super(context);
	}

	public MyHorizontalScrollView(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
	}

	public MyHorizontalScrollView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public void setScrollViewListener(ScrollViewListener scrollViewListener) {
		this.scrollViewListener = scrollViewListener;
	}

	@Override
	protected void onScrollChanged(int x, int y, int oldx, int oldy) {
		super.onScrollChanged(x, y, oldx, oldy);
		if (x <= 0+error) {
			if (scrollViewListener != null) {
				scrollViewListener.onScrollChanged(LEFT);
			}
		}
		if (x +getWidth() >= computeHorizontalScrollRange()-error) {
			if (scrollViewListener != null) {
				scrollViewListener.onScrollChanged(RIGHT);
			}
		}
		
	}

}